import { createRouter, createWebHashHistory } from "vue-router"
import type { RouteRecordRaw } from 'vue-router'
import type { App } from 'vue'
import { Layout } from './helper'

export const constantRouterMap: AppRouteRecordRaw[] = [
  {
    path: '/',
    component: Layout,
    name: 'Home',
    meta: { title: '首页' }
  },
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    name: 'Login',
    meta: { title: '登录' }
  },
  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    name: 'NotFound',
    meta: { title: '404' }
  }
]

const router = createRouter({
    history: createWebHashHistory(),
    strict: true,
    routes: constantRouterMap as RouteRecordRaw[],
    scrollBehavior: () => ({ left: 0, top: 0 })
  })

export const setupRouter = (app: App<Element>) => {
    app.use(router)
}

export default router